<?
require("required/dbconnect.php");
require_once("required/function.php");
require("required/header.php");


if (empty($_GET['product_type'])) {
    $product_type = "product";
    $title = "Product";
    checkAccess("allow_product_add", 1);
} else {
    $product_type = $_GET['product_type'];

    switch ($product_type) {
        case "product":
            checkAccess("allow_product_add", 1);
            $title = "Product";
            break;
        case "gift";
            checkAccess("allow_gift_management", 1);
            $title = "Gift";
            break;
        default:
            checkAccess("allow_product_add", 1);
            $title = "Product";
            break;
    }
}
?>
<script language="javascript">
				
    function checkExist(field,divName,showName) {
        var value = document.getElementById(field).value;
        if(value!=""){
							
            changeContent('required/js/checkExist.php?field='+field+'&value='+value+'&showName='+showName,divName)
        }
    }
	
    function getSubCat(catId) 
    {		
        changeContent("required/js/getsubcat.php?catid="+catId,"divSubcat")
    }
					
    function validatefrm(frm1)
    {
        if(document.frm1.cat_id.value=="")
        {
            alert("Please select main category");
            document.frm1.cat_id.focus();
            return false;
        }
        if(document.frm1.sub_cat.value=="")
        {
            alert("Please select sub category");
            document.frm1.sub_cat.focus();
            return false;
        }
        if(document.frm1.product_name_eng.value=="")
        {
            alert("Please enter product name");
            document.frm1.product_name_eng.focus();
            return false;
        }
        if(document.frm1.display_name.value=="")
        {
            alert("Please enter display name");
            document.frm1.display_name.focus();
            return false;
        }
        if(document.frm1.product_code.value=="")
        {
            alert("Please enter product code");
            document.frm1.product_code.focus();
            return false;
        }
        
        if(document.frm1.product_weight.value=="" || document.frm1.product_weight.value=="0")
        {
            alert("Please enter valid product weight");
            document.frm1.product_weight.focus();
            return false;
        }
        
						
        return true;
					
    }
</script>
<table width="100%"  cellpadding="5" cellspacing="0" height="300">

    <script language="JavaScript" type="text/javascript" src="required/js/goAjax.js"></script>
    <script language="JavaScript" src="required/js/calendarDateInput.js"></script>
    <SCRIPT language="JavaScript" src="required/js/tipmessage.js" type="text/javascript"></SCRIPT>
    <SCRIPT language="JavaScript" src="required/js/tipmessage_style.js" type="text/javascript"></SCRIPT>
    <DIV id="TipLayer" style="visibility:hidden;position:absolute;z-index:1000;top:-100"></DIV>	
    <td width="100%" align="left" valign="top">
        <form action="product_add2.php" name="frm1" method="post" onSubmit="return validatefrm(this)" enctype="multipart/form-data">
            <table width="100%">
                <td class="title" colspan="2"><strong>Add <?= $title ?></strong></td>
                <tr>
                    <td colspan="2" class="sub_title_line" ><br />Classification </td>
                </tr>

<?
$get_cat = mysql_query("select * from os_category order by id asc");
?>
                <tr>
                    <Td width="264">Main Category</Td>
                    <td width="1341">
                        <select name="cat_id" class="text" onChange="getSubCat(this.value)">
                            <option value="">Please Select</option>
<?
while ($c = mysql_fetch_array($get_cat, MYSQL_ASSOC)) {
    ?>
                                <option value="<?= $c['id'] ?>"><?= $c['name_eng'] ?></option>
                            <? } ?>
                        </select>

                    </td>
                </tr>
                <tr>
                    <td>Sub Category</td><td>
                        <div id="divSubcat">
                            <select name="sub_cat" class="text">
                                <option value="">Please Select main category</option>
                            </select>						
                        </div>
                    </td>
                </tr>
<?
if ($product_type == "product") {
    ?>
                    <tr>
                        <td>Display at website</td>
                        <td>
                            <select name="status" class="text">
                                <option value="1">Yes</option>
                                <option value="0">No</option>

                            </select>	
                        </td>
                    </tr>
                    <tr>
                        <td>Display at Latest</td>
                        <td>
                            <select name="show_at_latest" class="text">
                                <option value="1">Yes</option>
                                <option value="0">No</option>

                            </select>	
                        </td>
                    </tr>
                    <tr>
                        <td>Is Featured Product</td>
                        <td>
                            <select name="featured" class="text">
                                <option value="0">No</option>
                                <option value="1">Yes</option>								
                            </select>	
                        </td>
                    </tr>	

<? } else { ?>
                    <input type="hidden" name="status" value="1" />
                    <input type="hidden" name="show_at_latest" value="0" />

<? } ?>

                <tr>
                    <td colspan="2" class="sub_title_line" ><br />Product Details </td>
                </tr>

                <tr valign="top">
                    <td>Product name</td><td><input name="product_name_eng" id="product_name_eng" size="50" maxlength="200" class="text"  onBlur="checkExist('product_name_eng','divProductName','Product Name'); return false;">
                        <div id="divProductName"></div>
                    </td>
                </tr>
                <tr valign="top">
                    <td>Display Name</td><td><input name="display_name" id="display_name" size="50" maxlength="200" class="text" >

                    </td>
                </tr>
                <tr>
                    <td>Product weight</td><td><input name="product_weight" size="3" maxlength="3" class="text"> KG</td>
                </tr>
                <tr valign="top">
                    <td>Product code</td><td><input name="product_code" id="product_code" size="30" maxlength="20" class="text" onBlur="checkExist('product_code','divProductCode','Product code'); return false;">

                        <div id="divProductCode"></div>
                    </td>
                </tr>
                <tr valign="top">
                    <td>Order ID</td><td><input name="order_id" size="3" maxlength="5" >


                    </td>
                </tr>
                <input type="hidden" name="remark_eng">
                <tr valign="top">
                    <td>Picture</td>
                    <td>
                        <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> 
                        <input type="file" name="file" class=button size="30" />
                        <br />

                    </td>
                </tr>
                <tr valign="top">
                    <td>Picture Caption</td>
                    <td>
                        <input type="text" name="caption" size="30" maxlength="100" />                                  
                    </td>
                </tr>    
                <tr valign="top">
                    <td>Youtube Video ID</td><td><input name="youtube_id" size="50" maxlength="20" class="text">
                        <br />

                        e.g : http://www.youtube.com/v/<b>sdUUx5FdySs</b> 
                        <br />where <strong>sdUUx5FdySs</strong> is the Video Id
                        <br />
                        Leave it blank if no video included.
                    </td>
                </tr>
                <tr valign="top">
                    <td>Description </td>
                    <td valign="top">
<? include_once("fckeditor/fckeditor.php") ?>
<?php
$oFCKeditor = new FCKeditor('description_eng');
$oFCKeditor->ToolbarSet = 'DeswinBasic';
$oFCKeditor->BasePath = './fckeditor/';
$oFCKeditor->Value = "";
$oFCKeditor->Create();
?>

                    </td>
                </tr>


                <tr>
                    <td colspan="2" class="sub_title_line" ><br />Stock</td>
                </tr>

                <script type="text/javascript">
                    function addFloat(elems)
                    {
                        var value1=parseFloat(document.getElementById(elems).value);
                        document.getElementById(elems).value=value1.toFixed(2);
                    }
                    function addElement2() {
                        var ni = document.getElementById('myDiv');
                        var numi = document.getElementById('theValue');
                        var num = (document.getElementById('theValue').value -1)+ 2;
                        numi.value = num;
                        var newdiv = document.createElement('div');
                        var divIdName = 'description'+num;
                        newdiv.setAttribute('id',divIdName);
                        newdiv.innerHTML = '<tr><td>Description '+num+' <input type="text" name="desc'+num+'" class="contentfont" size=15 maxlength=100> &nbsp;&nbsp; '+ 
                           
                            'Unit Price <input type="text" name="unit_price'+num+'" class="contentfont" size=3 maxlength="10"> &nbsp;&nbsp; '
                            
                        ; 
													
                        ni.appendChild(newdiv);
                        document.getElementById("myDiv2").innerHTML="<input type=hidden value='"+num+"' name=totalitem>";
                    }
                </script>
                <tr valign="top">
                    <td>Stock Availability</td><td>

                        Description 1 <input type="text" name="desc1" size=15 maxlength="100"> &nbsp;&nbsp;
                       
                        Unit Price <input type="text" name="unit_price1" size=3 maxlength="10"> &nbsp;&nbsp;
                      

                        <input type="hidden" value="1" id="theValue" />

                        <div id="myDiv"></div>
                        <div id="myDiv2"><input type=hidden value='1' name=totalitem></div>
                        <p><a href=# onclick="addElement2()">Add New Option</a></p>
                    </td>
                </tr>
<?
if ($module_promotion == 1) {
    ?>
                    <tr>
                        <td colspan="2" class="sub_title_line" ><br />Promotion </td>
                    </tr>

                    <tr>
                        <td>Promotion</td>
                        <td>
                            <select name="promotion">
                                <option value="0">No</option>
                                <option value="1">Yes</option>
                            </select>
                        </td>
                    </tr>

                    <tr valign="top">
                        <td width="264">Promotion Start</td>
                        <td width="1341">
                            <script>DateInput('promotion_start', true, 'YYYY-MM-DD')</script>
                        </td>
                    </tr>
                    <tr valign="top">
                        <td width="264">Promotion End</td>
                        <td width="1341">
                            <script>DateInput('promotion_end', true, 'YYYY-MM-DD')</script>
                        </td>
                    </tr>
<? } else { ?>
                    <input type="hidden" name="promotion_start" value="0" />
                    <input type="hidden" name="promotion_end" value="0" />
                    <input type="hidden" name="promotion" value="0" />

<? } ?>



<?
if ($module_special_member == 1) {
    ?> 
                    <tr valign="top">
                        <td width="264">Promotion Open to</td>
                        <td width="1341">
                            <select name="promotion_target">
                                <option value="V">VIP Members</option>

                                <option value="B">Both VIP and Normal Members</option>
                            </select>
                        </td>
                    </tr>
<? } else { ?>
                    <input type="hidden" name="promotion_target" value="0" />

<? } ?>



<?
if ($module_redeemable == 1) {
    ?>
                    <tr>
                        <td colspan="2" class="sub_title_line" ><br />Redeemable Product</td>
                    </tr>
                    <tr>
                        <td>Redeemable</td>
                        <td>
                            <select name="redeemable" class="text">
                                <option value="0">No</option>
                                <option value="1">Yes</option>
                            </select>	
                        </td>
                    </tr>
                    <tr>
                        <td>Do not show at Product Page</td>
                        <td>
                            <select name="hide_at_products" class="text">
                                <option value="1">Yes</option>
                                <option value="0">No</option>
                            </select>	
                        </td>
                    </tr>
                    <tr>
                        <td>Points Required</td><td><input name="points_required" size="20" maxlength="6" class="text"></td>
                    </tr>
<? } else { ?>
                    <input type="hidden" name="points_required" value="0" />
                    <input type="hidden" name="hide_at_products" value="0" />
                    <input type="hidden" name="redeemable" value="0" />
<? } ?>    


                <tr valign="top">
                    <td><br>
                    </td>
                </tr>

                <tr>
                    <td colspan="2">



                        <input type="hidden" value="<?= $product_type ?>" name="product_type" />
                        <input type="submit" value="Submit" name="btnsubmit"></td>
                </tr>
            </table>
        </form>
    </td>

</table>
<? require("required/footer.php"); ?>